<?php

use App\Http\Controllers\OrderController;
use Illuminate\Support\Facades\Route;
use Laravel\Fortify\Http\Controllers\AuthenticatedSessionController;

//Route::get('/{action}', function(App\Http\Controllers\OrderController $index, $action){
//    return $index->$action();
//});

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

/*
|--------------------------------------------------------------------------
| 原始万能路由2
|--------------------------------------------------------------------------
|
*/
Route::any('/{class}/{action}', function($class, $action) {
    $class = ucfirst($class);
    $classRoute = "\\App\\Http\\Controllers\\" . $class;
    $ctrl = \App::make($classRoute);
    return \App::call([$ctrl, $action]);
})->middleware('CheckUser');

/*
|--------------------------------------------------------------------------
| 模块化万能路由3
|--------------------------------------------------------------------------
|
*/
Route::any('/{modules}/{class}/{action}', function($modules, $class, $action) {
    // 首字母大写，解决Linux识别大小写问题
    $modules = ucfirst($modules);
    $class = ucfirst($class);
    $action = ucfirst($action);
    $classRoute = "\\Modules\\".$modules."\\Http\\Controllers\\" . $class;
    $ctrl = \App::make($classRoute);
    return \App::call([$ctrl, $action]);
})->middleware('ApiInfo','CheckUser');

/*
|--------------------------------------------------------------------------
| 模块化万能路由4
|--------------------------------------------------------------------------
|
*/
Route::any('/{modules}/{module}/{class}/{action}', function($modules, $module, $class, $action) {

    // 首字母大写，解决Linux识别大小写问题
    $modules = ucfirst($modules);
    $module = ucfirst($module);
    $class = ucfirst($class);
    $action = ucfirst($action);

    define('MDS_MODULES', $modules);
    define('MDS_MODULE', $module);
    define('MDS_CLASS', $class);
    define('MDS_ACTION', $action);

    $file = "../Modules/$modules/Http/Controllers/$module/$class.php";
    if(!file_exists($file)){
        $class = "Defaults";
        define('MDS_DEFAULTS', 1);
    }

    $classRoute = "\\Modules\\".$modules."\\Http\\Controllers\\" . $module . '\\' . $class;
    $ctrl = \App::make($classRoute);
    return \App::call([$ctrl, $action]);

})->middleware('ApiInfo','CheckUser');//ApiInfo::记录访问记录,CheckUser::权限验证

/*
|--------------------------------------------------------------------------
| 以下是基础需要的一些杂乱路由
|--------------------------------------------------------------------------
|
*/
Route::any('/admin', function() {
    header("Location: /chinadmin/admin/index/index");
    exit;
});

Route::any('/', function() {
    header("Location: /Home/index/index/index");
    exit;
});

Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
    header("Location: /chinadmin/admin/index/index");
    exit;
})->name('dashboard');


/*
|--------------------------------------------------------------------------
| 以下测试使用
|--------------------------------------------------------------------------
|
*/

Route::resource('test',App\Http\Controllers\TestController::class);


